#include<stdio.h>
#include<stdlib.h>
#include<sys/socket.h>
#include<sys/un.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <string.h>

#define UNIX_FILE  "/home/linux/CProject/network/UNIX/unixfile_udp"
#define BACKLOG 5

int main(int args, const char * argv[]){

	int sockfd;
	int ret;
	struct sockaddr_un addr;
	socklen_t addrlen = sizeof(struct sockaddr_un);
	// BUFSIZ 8192
	char buf[BUFSIZ] = {0};  
	//1. 创建套接字：本地通信、UDP通信
	sockfd = socket(AF_UNIX, SOCK_DGRAM, 0);
	if(sockfd < 0){
		perror("socket");
		exit(0);
	}

	//2. 绑定通信结构体
	addr.sun_family = AF_UNIX;
	//定义本地文件
	strncpy(addr.sun_path, UNIX_FILE, sizeof(addr.sun_path)-1);

	//3. 客户端上送请求数据
	while(1){
		printf("Input->");
		fgets(buf, BUFSIZ, stdin);
		sendto(sockfd, buf, strlen(buf), 0, (struct sockaddr *)&addr, addrlen);
	}

	//4. 关闭套接字以及删除本地通信文件
	close(sockfd);
	return 0;
}
